<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>关注消息回复列表</title>
</head>
<body>
<div class="box">
    <section class="content-header">
        <h1 style="color: #f94877">
            {$data.name}
            <small style="color: #000;">关注后回复列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a><i class="fa fa-dashboard"></i> 公众号管理</a></li>
            <li class="active">公众号列表</li>
            <li class="active">消息回复消息列表</li>
        </ol>
    </section>
    <!-- /.box-header -->
    <section class="content">
    <div class="box-body">
        <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
            <div class="row">
                <div class="col-sm-8">
                    <div id="example1_filter" class="dataTables_length">
                        <label>
                            <input type="search" id="keyword" class="form-control input-sm" placeholder="标题" aria-controls="example1">
                        </label>
                        <button type="button" id="search" class="btn margin" style="background: #18bc9c;color: #ffffff;">搜索</button>
                        <button onclick="relist()" class="btn bg-aqua"><i class="fa fa-refresh"></i></button>
                        <button onclick="openAdd('{$data.id}')" class="btn bg-orange">添加回复消息</button>
                        <button type="button" id="btn_del" class="btn bg-red margin"><i class="fa fa-trash-o"></i> 删除</button>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                        <thead>
                        <tr role="row">
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 60px;">
                                <input id="allchecked" type="checkbox" style="margin-left: 10px">
                            </th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"  style="width: 190px;">消息ID</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"  style="width: 290px;">标题</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"  style="width: 361px;">类型</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"  style="width: 361px;">内容</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"  style="width: 361px;">图片链接</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"  style="width: 361px;">跳转链接</th>
                        </tr>
                        </thead>
                        <tbody id="tb">
                       </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
        <input type="hidden" value="{$data.id}" id="gid">
    <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    var _keyword = '';
    $(function(){
        getlist(_keyword);
        $('#search').click(function(){
            table.destroy();
            var keyword = $('#keyword').val();
            getlist(keyword);
        })
        //反选
        $('#allchecked').click(function(){
            $("[name = checkboxed]:checkbox").each(function () {
                $(this).prop("checked", !$(this).prop("checked"));
            });
        })
        $('#btn_del').click(function(){
            var chk_value =[];
            $('input[name="checkboxed"]').not("input:checked").each(function(){
                chk_value.push($(this).val());
            });
            if(chk_value == ''){
                layerAlert('请选择要删除的数据')
                return false;
            }
            var _id = $('#gid').val();
            $.ajax({
                type: 'post',
                cache: false,
                url:'{:url("tencent/deleteImgText")}',
                data: {chk_value:chk_value,type:1,tid:_id},//type 1为关注后回复消息 0为普通回复
                success:function (data) {
                    if(data.code == 0){
                        layerAlert('删除成功',function(){
                            table.destroy();
                            getlist(_keyword);
                        });
                    }else{
                        layerAlert('删除失败');
                    }
                },
                error:function(){
                    layerAlert('系统错误，请联系管理员');
                }
            })
        })
    })
    function openAdd(_id) {
        url = "{:url('tencent/addImgText')}" + "?tid=" + _id+"&type=1";//type 1为关注后回复消息 0为普通回复
        layerWindow('添加回复消息',url,'90%','90%');
    }
    function relist() {
        table.destroy();
        getlist(_keyword);
    }
    function getlist(_keyword) {
        var _id = $('#gid').val();
        $.ajax({
            type: 'post', cache: false,
            url:'{:url("admin/Tencent/getImgtextList")}',
            data: {keyword:_keyword,id:_id,type:1},//type 1为关注后回复消息 0为普通回复
            success: function(data) {
                if(data.code=="0")
                {
                    $("#tb tr").remove();
                    $.each(data.info,function(index,item){
                        var html='<tr role="row" class="odd" id="tr_'+item.id+'">';
                        html+='<td style="vertical-align: middle;"><input name="checkboxed" value="'+item.id+'" type="checkbox" style="margin-left: 10px"></td>';
                        html+='<td style="vertical-align: middle;">'+item.id+'</td>';
                        html+='<td style="vertical-align: middle;"><input type="text" value="'+item.title+'"></td>';
                        if(item.info_type == 1)
                            html+='<td style="vertical-align: middle;color: #449d44;">图文</td>';
                        if(item.info_type == 2)
                            html+='<td style="vertical-align: middle;color: #f1a417;">文本</td>';
                        html+='<td style="vertical-align: middle;"><input type="text" value="'+item.desc+'"></td>';
                        html+='<td style="vertical-align: middle;"><input type="text" value="'+item.img_url+'"></td>';
                        html+='<td style="vertical-align: middle;"><input type="text" value="'+item.t_url+'"></td>';;
                        html+='</tr>';
                        $("#tb").append(html);
                    });
                    table = $('#example1').DataTable({
                        "paging": true,
                        "lengthChange": false,
                        "lengthMenu": [[20],[20]],
                        "searching": false,
                        "ordering": false,
                        "info": true,
                        "language": {
                            "info": "展示第 <span style='color: red;'>_START_</span> 到 <span style='color: red;'>_END_</span> 个 共 <span style='color: red;'>_TOTAL_</span> 个公众号",
                            "paginate": {
                                "previous": "上一页",
                                "next": "下一页"
                            }
                        },
                        "autoWidth": true,
                    });
                }
            },
            error: function() {
                alert("发生系统错误,请与管理员联系！");
            }
        });
    }
</script>
</html>